<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">

    <form  method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered">


                    <input type="hidden" value="{$id}" id="uids">
                    <tr>
                        <th class="col-md-2">选择比赛<span class="form-required">*</span></th>
                        <td>
                            <select class="form-control" name="admin_settings[admin_theme]" name="mid"  id="getgameid">
                                <option value="" >请选择</option>

                                <volist name="games" id="game">
                                    <option value="{$game.id}"  data-score="{$game.score}" >{$game.name}</option>
                                </volist>


                            </select>
                        </td>
                    </tr>


                    <tr>
                        <th class="col-md-2">参赛方式<span class="form-required">*</span></th>
                        <td>
                            <label class="radio-inline">
                                <input type="radio"  name="stype" checked value="1">积分兑换
                            </label>
                            <label class="radio-inline">
                                <input type="radio"  name="stype" value="2"> 参赛券
                            </label>
                        </td>
                    </tr>


                    <tr id="scorebox">
                        <th class="col-md-2">积分<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text"  readonly id="score" />
                        </td>
                    </tr>


                    <th class="col-md-2">数量<span class="form-required">*</span></th>
                    <td>
                        <input class="form-control" type="text"   id="numner" />
                    </td>



                    <tr id="gamelog" style="display: none">
                        <th class="col-md-2">选择参赛券<span class="form-required">*</span></th>
                        <td>
                            <select class="form-control" name="admin_settings[admin_theme]"   id="getquan">
                                <option value="0" >请选择</option>

                            </select>
                        </td>
                    </tr>



                </table>

                <hook name="portal_admin_article_edit_view_main"/>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-primary js-ajax-submit" id="submits">立即报名</button>

                    </div>
                </div>
            </div>

        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });


    //选择比赛
    $("#getgameid").change("click", function() {
        // 当点击 myDiv 时触发的事件处理函数


        var id=$("#getgameid").val();
        var score=$("#getgameid").find("option:selected").data('score');

        $("#score").val(score);

        var  aac=$("#uids").val();
        $("#getquan").html(`<option value="0" >请选择</option>`);
        $.ajax({
            url:'getlist',
            data:{uid:aac,id:id},
            type:'post',
            dataType:'json',
            success:function (ret){
                var list=ret;

                var html='';

                for (var i=0;i<list.length;i++){
                    html+=" <option value="+ list[i].id +" >"+ list[i].name +"*"+ list[i].count +"</option>";
                }


                $("#getquan").append(html);
            }

        })



    });



    // 选择类型
    $('input[name=stype]').on('change', function() {

        var selectedValue = $(this).val(); //获取被选中的值

        if (selectedValue === '1'){


            $("#gamelog").hide();
            $("#scorebox").show();

            //其他操作...
        } else if (selectedValue === '2'){
            $("#scorebox").hide();
            $("#gamelog").show();

        }
    });


    //提交信息

    $("#submits").click(function (){

        var uid=$("#uids").val();
        var stype = $('input[name="stype"]:checked').val();
        var mid = $("#getgameid").val();
        var tid=$("#getquan").val();
        var number=$("#numner").val();

        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引


        $.ajax({
            url:'joingame',
            data:{uid:uid,stype:stype,mid:mid,tid:tid,numner:number},
            type:'post',
            dataType:'json',
            success:function (ret){
                layer.msg(ret.msg)
                var logid=ret.data.logid;
                console.log(ret);
                if (ret.code==1&&stype==1){
                    layer.open({
                        type: 2,
                        area: ['500px', '600px'],
                        content: '/user/admin_index/print?id='+logid,
                        success:function (){

                        },end:function (){
                            parent.layer.close(index); //再执行关闭
                        }

                    });
                }else if(ret.code==1){


                    layer.open({
                        type: 2,
                        area: ['500px', '600px'],
                        content: '/user/admin_index/printd?id='+logid,
                        success:function (){

                        },end:function (){
                            parent.layer.close(index); //再执行关闭
                        }

                    });
                }


            }

        })


    })



</script>
</body>
</html>
